package com.tyyw2.practice.common;


import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class CommandLineRunnerImpl implements ApplicationRunner {


    @Override
    public void run(ApplicationArguments args) throws Exception {

        ApplicationContext applicationContext = SpringUtil.getApplicationContext();
        if(applicationContext instanceof AnnotationConfigServletWebServerApplicationContext){
            int port =  ((AnnotationConfigServletWebServerApplicationContext) applicationContext).getWebServer().getPort();
            log.info("swagger2:http://localhost:{}/swagger-ui.html",port);
            log.info("swagger2:http://127.0.0.1:{}/swagger-ui.html",port);
        }
    }
}
